package com.gzx.spring.drools.service;

import com.gzx.risk.core.apis.context.ApiContext;
import com.gzx.risk.core.apis.result.RiskResult;
import com.gzx.risk.core.service.RiskService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class RiskLogService {
	@Resource
	private RiskService riskService;

	public void log(ApiContext ctx) {
		if (ctx.getRuleResult()) {
			log.info("final groupName:{},dataName:{},ruleResult:{}", ctx.getGroupName(), ctx.getDataName(),
					ctx.getRuleResult());
		} else {
			log.info("final groupName:{},dataName:{},ruleResult:{},rejectRule:{},rejectMsg:{}", ctx.getGroupName(),
					ctx.getDataName(), ctx.getRuleResult(), ctx.getRejectRule(), ctx.getRejectMsg());
		}

		for (RiskResult r : ctx.getResults()) {
			if (r.getRuleResult() == null || r.getRuleResult()) {
				log.info("groupName:{},dataName:{} true", r.getGroupName(), r.getDataName());
			} else {
				log.info("groupName:{},dataName:{},ruleResult:{},rejectRule:{},rejectMsg:{}", r.getGroupName(),
						r.getDataName(), r.getRuleResult(), r.getRejectRule(), r.getRejectMsg());
			}
		}
		riskService.log(ctx);
	}
}
